package com.soo.hoo.admin.config;

import com.soo.hoo.admin.component.DefaultWebSocketHandler;
import com.soo.hoo.admin.component.DefaultWebSocketInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * <p>websocket配置类</p>
 *
 * @author 杨燚
 * @since 2023/6/6
 */
@EnableWebSocket
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private DefaultWebSocketHandler webSocketHandler;

    @Resource
    private DefaultWebSocketInterceptor webSocketInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketHandler,"/ws","/ws/**")
                .addInterceptors(webSocketInterceptor)
                .setAllowedOrigins("*");
    }
}
